Data Description: The IPL is professional cricket t20 league championship started in India in 2008. It was initiated by BCCI with 8 franchises comprising players across the world. The first IPL auction was held in 2008 for ownership of the teams for 10 years, with base price of USD 50 Billion. The franchises acquire players through an auction that is conducted every year. However , there are several rules imposed by the IPL. The performance of the players could be measured many ways. Although the IPL follows twenty20 format of the game, it is possible that the performance of the players in the other format of the game such as test and ODI matches can influence the player pricing The data set consist of performance 0f 130 players measured through various performance measure metrics such as batting , bowling etc.
coefficient to understand what features of players are influencing their SOLD PRICE
import pandas as pd
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score, f1_score, confusion_matrix, auc, roc_curve
from sklearn.preprocessing import StandardScaler
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
from sklearn.preprocessing import LabelEncoder
from sklearn.metrics import confusion_matrix,accuracy_score,classification_report
import re
from sklearn.preprocessing import LabelEncoder
from sklearn.metrics import mean_squared_error,mean_absolute_error,r2_score
from sklearn.ensemble import RandomForestRegressor
from sklearn.linear_model import LinearRegression,Ridge,Lasso
from sklearn.metrics import mean_squared_error,mean_absolute_error,r2_score
from statsmodels.formula.api import ols
from sklearn.tree import DecisionTreeRegressor
dt=pd.read_csv('IPL IMB381IPL2013.csv')
dt.head()
dt.columns
dt.dtypes
dt.isnull().sum()
dt.shape
dt['AUCTION YEAR'].unique()
dt_Allrounder=dt[dt['PLAYING ROLE']=='Allrounder']
dt_Allrounder=dt_Allrounder.sort_values('SOLD PRICE',axis=0,ascending=False)
dt_Allrounder['PLAYING ROLE'].unique()
dt_Bowler=dt[dt['PLAYING ROLE']=='Bowler']
dt_Bowler=dt_Bowler.sort_values('SOLD PRICE',axis=0,ascending=False)
dt_Batsman=dt[dt['PLAYING ROLE']=='Batsman']
dt_Batsman=dt_Batsman.sort_values('SOLD PRICE',axis=0,ascending=False)
dt_WKeeper=dt[dt['PLAYING ROLE']=='W. Keeper']
dt_WKeeper=dt_WKeeper.sort_values('SOLD PRICE',axis=0,ascending=False)
dt['TEAM'].unique()
dt['TEAM']=dt['TEAM'].replace(['CSK+','RCB+','MI+','DD+','KKR+','DC+','RR+','KXIP+'],
['CSK','RCB','MI','DD','KKR','DC','RR','KXI'])
dt['TEAM']=dt['TEAM'].replace(['KXI'],['KX'])
data = pd.DataFrame(dt.head(30).groupby(['TEAM', 'AUCTION YEAR'])['SOLD PRICE'].sum()).reset_index()
#fig = px.line(data, x='Year', y='Amount', color='Team', symbol='Team')
#fig = px.bar(data, x='AUCTION YEAR', y='SOLD PRICE', color='TEAM')#, symbol='Team')
fig = px.bar(data, x='TEAM', y='SOLD PRICE', color='AUCTION YEAR')#, symbol='Team')
fig.update_layout(title_text = "Overall comparision of different team spends")
fig.show()
fig = px.line(data, x='AUCTION YEAR', y='SOLD PRICE', color='TEAM', symbol='TEAM')
#fig = px.bar(data, x='Year', y='Amount', color='Team')#, symbol='Team')
fig.update_layout(title_text = "Overall comparision of different team spends")
fig.show()
data = pd.DataFrame(dt_Batsman.head(30).groupby(['TEAM', 'PLAYER NAME'])['SOLD PRICE'].sum()).reset_index()
#fig = px.line(data, x='Year', y='Amount', color='Team', symbol='Team')
fig = px.bar(data, x='PLAYER NAME', y='SOLD PRICE', color='TEAM')#, symbol='Team')
fig.update_layout(title_text = "Overall comparision of different team spends on Batsman")
fig.show()
fig =px.bar(dt_Batsman.head(30), y="PLAYER NAME", x="SOLD PRICE", text='AVE',color='T-RUNS',orientation='h', height=600)
fig.update_layout(title_text = "Top-30 Batsman Auction Buys w.r.t Total runs and avarege")
fig.show()
fig =px.bar(dt_Batsman.head(30), y="PLAYER NAME", x="SOLD PRICE", text='ODI-RUNS-S',color='ODI-SR-B',orientation='h', height=600)
fig.update_layout(title_text = "Top-30 Batsman Auction Buys w.r.t ODI runs and Str Rate")
fig.show()
fig =px.bar(dt_Batsman.head(30), y="PLAYER NAME", x="SIXERS", text='T-RUNS',color='SOLD PRICE',orientation='h', height=600)
fig.update_layout(title_text = "Top-30 Batsman Auction Buys w.r.t Total runs and Sixers")
fig.show()
data = pd.DataFrame(dt_WKeeper.head(30).groupby(['TEAM', 'PLAYER NAME'])['SOLD PRICE'].sum()).reset_index()
#fig = px.line(data, x='Year', y='Amount', color='Team', symbol='Team')
fig = px.bar(data, x='PLAYER NAME', y='SOLD PRICE', color='TEAM')#, symbol='Team')
fig.update_layout(title_text = "Overall comparision of different team spends on Wicket Keeper")
fig.show()
fig =px.bar(dt_WKeeper.head(30), y="PLAYER NAME", x="SOLD PRICE", text='AVE',color='T-RUNS',orientation='h', height=600)
fig.update_layout(title_text = "Top-30 Wk Auction Buys w.r.t Total runs and avarege")
fig.show()
fig =px.bar(dt_WKeeper.head(30), y="PLAYER NAME", x="ODI-SR-B", text='SOLD PRICE',color='SOLD PRICE',orientation='h', height=600)
fig.update_layout(title_text = "Top-30 Wk Auction Buys w.r.t ODI runs and Str Rate")
fig.show()
fig =px.bar(dt_WKeeper.head(30), y="PLAYER NAME", x="SIXERS", text='T-RUNS',color='SOLD PRICE',orientation='h', height=600)
fig.update_layout(title_text = "Top-30 Wk Auction Buys w.r.t Total runs and Sixers")
fig.show()
data = pd.DataFrame(dt_Allrounder.head(30).groupby(['TEAM', 'PLAYER NAME'])['SOLD PRICE'].sum()).reset_index()
#fig = px.line(data, x='Year', y='Amount', color='Team', symbol='Team')
fig = px.bar(data, x='PLAYER NAME', y='SOLD PRICE', color='TEAM')#, symbol='Team')
fig.update_layout(title_text = "Overall comparision of different team spends on Allrounder")
fig.show()
fig =px.bar(dt_Allrounder.head(30), y="PLAYER NAME", x="SOLD PRICE", text='AVE',color='T-RUNS',orientation='h', height=600)
fig.update_layout(title_text = "Top-30 Allrounder Auction Buys w.r.t Total runs and avarege")
fig.show()
fig =px.bar(dt_Allrounder.head(30), y="PLAYER NAME", x="SOLD PRICE", text='ODI-RUNS-S',color='ODI-SR-B',orientation='h', height=600)
fig.update_layout(title_text = "Top-30 Allrounder Auction Buys w.r.t ODI runs and Str Rate")
fig.show()
fig =px.bar(dt_Allrounder.head(30), y="PLAYER NAME", x="SOLD PRICE", text='T-RUNS',color='T-RUNS',orientation='h', height=600)
fig.update_layout(title_text = "Top-30 Allrounder Auction Buys w.r.t Total runs and Sixers")
fig.show()
fig =px.bar(dt_Allrounder.head(30), y="PLAYER NAME", x="SOLD PRICE", text='T-WKTS',color='SIXERS',orientation='h', height=600)
fig.update_layout(title_text = "Top-30 Allrounder Auction Buys w.r.t Total Wickets and Sixers")
fig.show()
fig =px.bar(dt_Bowler.head(30), y="PLAYER NAME", x="T-WKTS", text='SR-BL',color='SOLD PRICE',orientation='h', height=600)
fig.update_layout(title_text = "Top-30 Bowler Auction Buys w.r.t Total-WKTS runs and bowling Strikerate")
fig.show()
fig =px.bar(dt_Bowler.head(30), y="PLAYER NAME", x="ODI-WKTS", text='ODI-SR-BL',color='SOLD PRICE',orientation='h', height=600)
fig.update_layout(title_text = "Top-30 Bowler Auction Buys w.r.t ODI-WKTS runs and Strikerate")
fig.show()
fig =px.bar(dt_Bowler.head(30), y="PLAYER NAME", x="ECON", text='SR-BL',color='SOLD PRICE',orientation='h', height=600)
fig.update_layout(title_text = "Top-30 Bowler Auction Buys w.r.t Economy and Strikerate")
fig.show()
fig =px.bar(dt_Bowler.head(30), y="PLAYER NAME", x="RUNS-C", text='T-WKTS',color='SOLD PRICE',orientation='h', height=600)
fig.update_layout(title_text = "Top-30 Bowler Auction Buys w.r.t T20-Runs conc and Wkts")
fig.show()
fig =px.bar(dt_Allrounder.head(30), y="PLAYER NAME", x="T-WKTS", text='SR-BL',color='SOLD PRICE',orientation='h', height=600)
fig.update_layout(title_text = "Top-30 Allrounder Auction Buys w.r.t Total-WKTS runs and Strikerate")
fig.show()
fig =px.bar(dt_Allrounder.head(30), y="PLAYER NAME", x="ODI-WKTS", text='ODI-SR-BL',color='SOLD PRICE',orientation='h', height=600)
fig.update_layout(title_text = "Top-30 Allrounder Auction Buys w.r.t ODI-WKTS runs and Strikerate")
fig.show()
fig =px.bar(dt_Allrounder.head(30), y="PLAYER NAME", x="WKTS", text='AVE-BL',color='SOLD PRICE',orientation='h', height=600)
fig.update_layout(title_text = "Top-30 Allrounder Auction Buys w.r.t T20-WKTS runs and Average")
fig.show()
fig =px.bar(dt_Allrounder.head(30), y="PLAYER NAME", x="ECON", text='SR-BL',color='SOLD PRICE',orientation='h', height=600)
fig.update_layout(title_text = "Top-30 Allrounder Auction Buys w.r.t Economy and Strikerate")
fig.show()
fig =px.bar(dt_Bowler.head(30), y="PLAYER NAME", x="RUNS-C", text='WKTS',color='SOLD PRICE',orientation='h', height=600)
fig.update_layout(title_text = "Top-30 Allrounder Auction Buys w.r.t T20-Runs conc and Wkts")
fig.show()
teams = dt.TEAM.unique()
import plotly.graph_objects as go
for team in teams:
data = dt[dt['TEAM'] == team].groupby('AUCTION YEAR')['SOLD PRICE'].sum().to_frame('SOLD PRICE').reset_index()
#fig = px.line(data, x = 'AUCTION YEAR', y = 'SOLD PRICE', title = f"{team}'s spent amount", text=data.index)
#fig.add_bar(x = data.index, y = 'Amount')
#fig.update_traces(textposition="top right")
#fig.show()
fig = px.bar(data, x = 'AUCTION YEAR', y = 'SOLD PRICE', color='SOLD PRICE')#, symbol='Team')
fig.update_layout(title_text = f"{team}'s spent amount")
fig.show()
teams = dt.COUNTRY.unique()
import plotly.graph_objects as go
for team in teams:
data = dt[dt['COUNTRY'] == team].groupby('AUCTION YEAR')['SOLD PRICE'].sum().to_frame('SOLD PRICE').reset_index()
#fig = px.line(data, x = 'AUCTION YEAR', y = 'SOLD PRICE', title = f"{team}'s spent amount", text=data.index)
#fig.add_bar(x = data.index, y = 'Amount')
# fig.update_traces(textposition="top right")
# fig.show()
fig = px.bar(data, x = 'AUCTION YEAR', y = 'SOLD PRICE', color='SOLD PRICE')#, symbol='Team')
fig.update_layout(title_text = f"{team}'s spent amount")
fig.show()
teams = dt['PLAYING ROLE'].unique()
import plotly.graph_objects as go
for team in teams:
data = dt[dt['PLAYING ROLE'] == team].groupby('AUCTION YEAR')['SOLD PRICE'].sum().to_frame('SOLD PRICE').reset_index()
#fig = px.line(data, x = 'AUCTION YEAR', y = 'SOLD PRICE', title = f"{team}'s spent amount", text=data.index)
#fig.add_bar(x = data.index, y = 'Amount')
#fig.update_traces(textposition="top right")
# fig.show()
fig = px.bar(data, x = 'AUCTION YEAR', y = 'SOLD PRICE', color='AUCTION YEAR')#, symbol='Team')
fig.update_layout(title_text = f"{team}'s spent amount")
fig.show()
sort_vals = dt.sort_values(by='SOLD PRICE',ascending=False) #.head(50)
fig = px.bar(sort_vals, x="TEAM", y="SOLD PRICE",
color="PLAYING ROLE", barmode = 'group',text='AUCTION YEAR')
fig.show()